package com.hopes.bizz.poll.town.handler;

import com.baomidou.mybatisplus.extension.service.IService;
import com.hopes.bizz.poll.common.constant.OmConstant;
import com.hopes.bizz.poll.om.entity.BaseOmDataEntity;
import com.hopes.bizz.poll.om.service.*;
import com.hopes.bizz.poll.town.entity.BaseTownOmDataEntity;
import com.hopes.bizz.poll.town.service.PollTownDayService;
import com.hopes.bizz.poll.town.service.PollTownHourService;
import com.hopes.bizz.poll.town.service.PollTownMinService;
import com.hopes.bizz.poll.town.service.PollTownRtDataHisService;
import lombok.AllArgsConstructor;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @author lyb
 * @version 1.0
 * @date 2023/10/7 13:26
 */

@Component
@AllArgsConstructor
public class PollHisDataFactory {

    private static final Map<Integer, IService<? extends BaseOmDataEntity>> pollMap = new ConcurrentHashMap<>(8);

    private static final Map<Integer, IService<? extends BaseTownOmDataEntity>> pollTownMap = new ConcurrentHashMap<>(8);

    private final PollRtDataHisService pollRtDataHisService;

    private final PollMinService pollMinService;

    private final PollHourService pollHourService;

    private final PollDayService pollDayService;

    private final PollMonthService pollMonthService;

    private final PollYearService pollYearService;


    @PostConstruct
    public void init() {
        pollMap.put(OmConstant.DATA_TYPE_RT, pollRtDataHisService);
        pollMap.put(OmConstant.DATA_TYPE_MIN, pollMinService);
        pollMap.put(OmConstant.DATA_TYPE_HOUR, pollHourService);
        pollMap.put(OmConstant.DATA_TYPE_DAY, pollDayService);
        pollMap.put(OmConstant.DATA_TYPE_MONTH, pollMonthService);
        pollMap.put(OmConstant.DATA_TYPE_YEAR, pollYearService);
    }


    public IService<? extends BaseOmDataEntity> getPollService(Integer dataType) {
        return pollMap.get(dataType);
    }

    public IService<? extends BaseTownOmDataEntity> getTownPollService(Integer dataType) {
        return pollTownMap.get(dataType);
    }
}
